from common.base import *
from common.browser import *


class Receiving_backstage(Base):
    # 点击关闭弹框
    def close(self):
        self.click((By.XPATH, '//*[@id="panelCloud"]/div[1]/span'))

    # 点击登录跳转按钮
    def cloudLogin(self):
        self.click((By.ID, 'cloudLogin'))

    # 输入用户名
    def input_username(self, username):
        self.send_keys((By.NAME, 'username'), username)

    # 密码输入框
    def input_password(self, password):
        self.send_keys((By.NAME, 'password'), password)

    # 点击登录按钮
    def btn(self):
        self.click((By.CLASS_NAME, 'btn-a'))

    # #切换frame
    # def frame(self):
    #     self.switch_frame('menu-frame')

    # 进入会员管理中心
    def member(self):
        self.find_element((By.XPATH, '//*[@id="menu-ul"]/li[8]')).click()

    # 点击输入会员名称
    def name(self, name):
        self.send_keys((By.XPATH, '/html/body/div[3]/form/input[3]'), name)

    # 点击搜索
    def btn_search(self):
        self.click((By.XPATH, '/html/body/div[3]/form/input[4]'))

    # 点击查看地址
    def View_address(self):
        self.click((By.LINK_TEXT, '收货地址'))


if __name__ == '__main__':
    driver = open_browser()
    a = Receiving_backstage(driver)
    a.get('http://172.16.140.91/ecshop/admin/privilege.php?act=login')
    a.close()
    a.cloudLogin()
    a.input_username('admin')
    a.input_password('admin1234')
    a.btn()
    a.switch_frame('menu-frame')
    a.member()
    a.switch_default_content()
    a.switch_frame('main-frame')
    a.name('weilong')
    a.btn_search()
    sleep(3)
    a.View_address()
    sleep(5)
    a.quit()
